#ifndef _LABFISDAQ_H
#define _LABFISDAQ_H   1

extern "C" {
#include <stdio.h>
#include <termios.h>
}

///////////////////////////////////////////////////////////////////////////////
//
// common definitions for Lab Fisica experiments
//

#define LFDAQ_SYSERR			(1001)
#define LFDAQ_QUITSCAN			(1002)
#define LFDAQ_EOF			(1003)
#define LFDAQ_STDINRDY			(1004)
#define LFDAQ_TIMEOUT			(1005)

///////////////////////////////////////////////////////////////////////////////
//
// class declarations
//

//
// class labFisTermIoHandler
// - used to modify termilan I/O for non-blocking I/O with automatic
//   restoration of initial data when the object is destroyed
//

class labFisTermIoHandler {
 private:
  bool isTerminal;
  int fn;
  struct termios attr;
 public:
  labFisTermIoHandler();
  labFisTermIoHandler(FILE *input);
  virtual ~labFisTermIoHandler();
  
  void SetImmedNoecho();
  void Reset();
};

////////////////////////////////////////////////////////////////////////////////
//
// function declarations
//

int comedi_internal_trigger(comedi_t *dev,
			    unsigned int subd,
			    unsigned int trignum
			    );

void labFisNonBlockingTty(FILE* input);
void labFisRestoreTty(FILE* input);

int labFisScanCmdTest(comedi_t *cifh,
		      comedi_cmd *cmdp
		      );

void labFisScanPrepare(comedi_t *cifh,
		     int subdev,
		     comedi_cmd *cmdp,
		     unsigned int triggerType,
		     unsigned int sampleRate,
		     unsigned int scanType,
		     unsigned int scanNum,
		     unsigned int *chanList,
		     unsigned int chanListLen
		     );

int labFisScanRead(comedi_t *dev,
		   int subdev,
		   sampl_t *buf, unsigned int bufSiz,
		   long int timeout, unsigned int timeoutTot);

//--- inherited from Comedi demo directory with minor modifications
void dump_cmd(FILE *out, comedi_cmd *cmd);

#endif
